package nicg.st.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;

import nicg.st.entity.Bar;
import nicg.st.entity.IndicatorDataDetail;
import nicg.st.entity.IndicatorDetail;
import nicg.st.entity.PieVO;
import nicg.st.entity.Radar;
import nicg.st.entity.ResultList;
import nicg.st.entity.SchemeList;
import nicg.st.service.ResultService;
import nicg.st.service.XmlService;
import nicg.st.service.evaldataenterservice.EvalDataEnterService;
import nicg.st.util.Log;

/**
 * @author
 * @Description
 * @date 2019/11/3 23:24
 */
@RestController
@RequestMapping("/api/result")
public class ResultController {
	@Autowired
	ResultService resultService;
	@Autowired
	XmlService xmlService;
	@Autowired
	EvalDataEnterService evalDataEnterService;

	@RequestMapping(value = "/findSchemeSum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public int findSchemeSum() {

//    	xmlService.receiveDocumentToDB("./receive/send.xml");
//    	File file = new File("./receive/send.xml");
//    	if(file.isFile() && file.exists()){
//    		file.delete();
//    	}
//    	Dtml dtml = new Dtml();
//		if(dtml.init()){
//			String currentId = dtml.getUnitId();
//			getSingleUnitJsonResult res = dtml.getSingleUnitJson(currentId);
////			System.out.println(currentId);
////			System.out.println(res.json);
////			System.out.println("==========");
////			getUnitAttrResult value = dtml.getUnitAttr(currentId, "JDLX");
////			System.out.println(value.attrValue);
////			value = dtml.getUnitAttr(currentId, "RYLX");
////			System.out.println(value.attrValue);
//		}
		return resultService.findSchemeSum();
	}

	@RequestMapping(value = "/findSchemeSearchSum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public int findSchemeSearchSum(String startTime, String endTime) {
		return resultService.findSchemeSearchSum(startTime, endTime);
	}

	@RequestMapping(value = "/findSchemeSearchNameSum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public int findSchemeSearchNameSum(String searchName) {
		return resultService.findSchemeSearchNameSum(searchName);
	}

	@RequestMapping(value = "/findSchemeSearchAllSum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public int findSchemeSearchAllSum(String startTime, String endTime, String searchName) {
		return resultService.findSchemeSearchAllSum(startTime, endTime, searchName);
	}

	@RequestMapping(value = "/findScheme", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<SchemeList> findScheme() {

		return resultService.findScheme();
//        return resultService.findSchemeByPage(page);
	}

	@RequestMapping(value = "/findSchemeByPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public List<ResultList> findScheme(Integer page) {
		return resultService.findSchemeByPage(page);
	}

	@RequestMapping(value = "/findSchemeSearchByPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public List<SchemeList> findSchemeSearchByPage(Integer page, String startTime, String endTime) {
		return resultService.findSchemeSearchByPage(page, startTime, endTime);
	}

	@RequestMapping(value = "/findSchemeSearchNameByPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public List<SchemeList> findSchemeSearchNameByPage(Integer page, String searchName) {
		return resultService.findSchemeSearchNameByPage(page, searchName);
	}

	@RequestMapping(value = "/findSchemeSearchAllByPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public List<ResultList> findSchemeSearchAllByPage(Integer page, String startTime, String endTime,
			String searchName) {
		return resultService.findSchemeSearchAllByPage(page, startTime, endTime, searchName);
	}

	@RequestMapping(value = "/findIndicator", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<IndicatorDataDetail> findIndicator(int schemeId) {
		return resultService.findIndicatorBySchemeId(schemeId);
	}

	@RequestMapping(value = "/buildIndicator", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<IndicatorDetail> buildIndicaor(int schemeId) {
		return resultService.buildIndicator(schemeId);
	}

	@RequestMapping(value = "/findLevelTwoScore", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<Double> findLevelTwoScore(int schemeId) {
		return resultService.findLevelTwoScore(schemeId);
	}

	// 一级指标权重饼图
	@RequestMapping(value = "/buildPieOne", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<PieVO> buildPieOne(int schemeId) {
		return resultService.buildPieOne(schemeId);
	}

	// 一级指标评分雷达图
	@RequestMapping(value = "/buildRadar", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<Radar> buildRadar(int schemeId) {
		return resultService.buildRadar(schemeId);
	}

	// 二级指标评分柱状图
	@RequestMapping(value = "/buildBar", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<Bar> buildBar(int schemeId, String levelOne) {
		return resultService.buildBar(schemeId, levelOne);
	}

	// 二级指标权重饼状图
	@RequestMapping(value = "/buildPieTwo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<Bar> buildPieTwo(int schemeId, String levelOne) {
		return resultService.buildPieTwo(schemeId, levelOne);
	}

	@RequestMapping(value = "/deletScheme", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String deleteScheme(int id) {
		return resultService.deleteScheme(id);
	}

	// 评估结果
	@RequestMapping(value = "/getResultTag1", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String resultTag1(int schemeId, int userId) {
		return resultService.getResultTag1(schemeId, userId);
	}

	/**
	 * 行动决策
	 */
	@RequestMapping(value = "/getschemeoutside", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getSchemeOutside(String aramyName) {
		System.out.println(aramyName);
		return evalDataEnterService.getSchemeOutside(aramyName);
	}

	// 返回UnitXml文件解析后的list集合信息(http://localhost:8101/api/indicatorsystem/unitXmlInformation)
	@RequestMapping(value = "/unitXmlInformation", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getUnitXmlInformation() {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return evalDataEnterService.getUnitXmlInformationList();
	}

	@RequestMapping(value = "/saveList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public void getInformation(@RequestBody List<String> selectArr) {
		System.out.println(JSON.toJSONString(selectArr));
	}

	// 调用动态名录借口获取名录树列表
	@RequestMapping(value = "/getTreeNodes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getTreeNodes(String type) {
		return resultService.getTreeNodes(type);
	}
}